#!/usr/bin  python
# _*_ coding:utf-8 _*_
"""
----------------------------------
    File Name: hospital
    Description:
        Author: lhw
        Date: 2020/6/2
-----------------------------------
"""
from rest_framework import serializers, exceptions
from EducationContent import models
from rest_framework.exceptions import ValidationError


class HospitalModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Hospital
        fields = ("id", "hospital_name", "hospital_address", "hospital_logo")
        extra_kwargs = {
            "hospital_name": {
                'required': True,
            }
        }

    def validate_hospital_name(self, value):
        if not models.Hospital.objects.filter(hospital_name=value, is_delete=False):
            return value
        raise ValidationError("this hospital already exist")
